<!--
 * @Descripttion: 
 * @version: 
 * @Author: mmzhang
 * @Date: 2021-07-21 10:45:02
 * @LastEditTime: 2022-12-19 13:47:18
-->
<template>
  <div class="group-report">
    <dt-search ref="search" :labelWidth="85" :xl="5" :xlBtn="7">
      <Poptip v-model="exportVisible" trigger="hover" transfer>
        <Button type="primary" v-if="unlocking('0207020601')">导出</Button>
        <div slot="content">
          <div class="export-btn hand" @click="exportExcelFun(0)">全部导出</div>
          <div class="export-btn hand" @click="exportExcelFun(1)">按事业部导出</div>
          <div class="export-btn hand" @click="exportExcelFun(2)">按公司导出</div>
          <div class="export-btn hand" @click="exportExcelFun(3)">按事业处导出</div>
          <div class="export-btn hand" @click="exportExcelFun(4)">按案场导出</div>
          <div class="export-btn hand" @click="exportExcelFun(5)">按产品导出</div>
        </div>
      </Poptip>
      <Button type="primary" class="operation" @click="operationClick"
        v-if="unlocking('0207020602')">查看导出记录</Button>
    </dt-search>
    <dt-grid ref='table' :columns="columns" :onFetch='onFetch' :tree="{}"></dt-grid>
    <operation-record ref="operationRecord"></operation-record>
  </div>
</template>
<script>
  import columnConfig from './components/fullPayColumn'
  import businessCommonMgr from '@/biz/businessReport/businessCommon'
  import fullPayMgr from '@/biz/businessReport/fullPay'
  import tool from '@/common/tool.js'
  import dt from '@dt/dt'
  import watermark from '@/common/waterMark'
  import fullPaySearch from './components/fullPaySearch'
  export default {
    data() {
      return {
        exportVisible: false,
        formValidate: {
          companyIds: [],
          checkTime: tool.currentMonth(),
          buildingName: '',
        },
        tableData: [],
        columns: [],
        filterParams: {}
      }
    },
    watch: {
      $route(to, from) {
        if (to.name != 'fullPayReport') {
          return false
        }
        if (from.name != 'contractSummary') {
          this.$refs.search.reset()
          watermark.set()
          this.$refs.table.fetch()
        }
      }
    },
    components: {},
    created() {},
    mounted() {
      //发送this 到 js 文件里
      columnConfig.sendThis(this)
      this.columns = columnConfig.columns
      this.$refs.table.init(this)
      this.$refs.search.init(this.$refs.table, new fullPaySearch(this).options(), this
        .formValidate)
      this.$refs.table.fetch()
      watermark.set()
    },
    methods: {
      operationClick() {
        this.$refs.operationRecord.show('export_groupReport', 'M_10', '', 'logtype')
      },
      // 导出
      exportExcelFun(type) {
        if (!this.tableData.length) {
          this.$Message.warning('暂无数据！')
          return false
        }
        let params = Object.assign(this.filterParams)
        params.exportType = type

        fullPayMgr
          .exportFullPaymentStatistic(params)
          .then((res) => {})
          .catch((err) => {})
      },

      onFetch(data) {
        let params = Object.assign(data)

        params.startTime = params.checkTime[0]
        params.endTime = params.checkTime[1]

        this.filterParams = { ...params }

        return fullPayMgr
          .getFullPaymentStatistics(params)
          .then((res) => {
            if (params.buildingName === '' || params.buildingName === null) {
              res.forEach((item) => {
                this.$refs.table.treeExpand(item)
              })
            } else {
              this.resolveExpand(res)
            }
            this.tableData = res;
            return res
          })
      },
      // 处理列表展开
      resolveExpand(arr) {
        arr.forEach(item => {
          this.$refs.table.treeExpand(item)
          if (item.children && item.children.length) {
            this.resolveExpand(item.children)
          }
        })
      },
      // 跳转签约汇总
      linkOrderSummaryFun(row) {
        let params = {
          orgId: row.level == 5 ? row.housesId : row.orgEndId,
          checkTime: this.filterParams.checkTime,
          productId: row.productId,
          containDate: ['6'],
          checkIndex: null
        }
        dt.memory.set('conSumOrder_params', params)

        this.$router.push({
          name: 'contractSummary',
          params: {
            showNetWorthFlag: true
          }
        })
      },
    },
  }
</script>
<style lang="scss" scoped>
  .group-report {
    padding: 20px;
    width: 100%;

    .ivu-spin-fix {
      background-color: rgba(255, 255, 255, 0.35);
      width: calc(100% - 200px);
      left: 200px;
    }

    .dt-search {
      ::v-deep .ivu-form {
        .ivu-col:nth-child(2) {
          .ivu-form-item-content {
            margin-left: 0 !important;
          }
        }

        .ivu-col-span-xl-3 {
          .ivu-form-item-content {
            margin-left: 0 !important;
          }
        }

        .ivu-form-item-label {
          padding: 10px 5px 10px 0;
        }

        .ivu-form-item {
          margin-bottom: 20px;
        }

        .ivu-select-multiple .ivu-tag {
          max-width: 55%;
          padding: 0;
          margin: 3px 0;
        }
      }

    }
  }

  .export-btn {
    line-height: 30px;
    cursor: pointer;
    color: #2d8cf0;
    text-align: center;
    border-bottom: 1px #e8eaec solid;
  }
</style>